/*
 * @: 
 * @version: 1.0
 * @Author: ziwei
 * @Date: 2021-09-05 14:55:47
 * @LastEditors: ziwei
 * @LastEditTime: 2021-11-28 20:56:06
 */
import React from 'react';
import prefixModel from "./prefixModel";
import { ReactDOM } from 'react-dom';

function dva() {
    const app={
        _models:[],//存放model的数组
        model,//函数用来往 model数组中添加model元素
        router,
        _router:null,//
        start//开启渲染
    }
    function model(modelObject) {
        const prefixModel = prefixNamespan(modelObject);
        app._models.push(prefixModel);
        app._models.push(modelObject)
    }

    function router(routerConfig) {
        app._router = routerConfig;
    
    }
    let initReducers = {};
    function start(selector) {
        for(const model of app._models){
            initReducers[model.namespace] = getReducer(model);
        }
        let rootReducer = createReducer();
        const sagas = getSagas(app);
        let sagaMiddleware = createSagaMiddle();
    }
    //把每个model中的effects编程saga
    function getSagas(app) {
        let sagas = [];
        for(let model of app._models){
            sagas.push(getSaga(model.effects,model))
        }
        return sagas
    }
    return app
}

function getSaga(effect,model) {
    return function*() {
        for(const key in effects){
            const watcher = getWatcher(key,model.effects[key],model);
            yield sagaEffects.fork(watcherSaga);//开启一个新的子进程去执行
        }
    }
}

function getWatcher(key,effect,model) {
    return function *() {
        yield sagaEffects.
    }
}

function getReduce(model) {
    let {state:initialState,reducers} = model;
    let reducer = (state = initialState,action)=>{
        let reducer = reducers[action.type];
    }
}

export default dva;

//provider => store
//store => reducere
